package mylab.io.core.codec;

import java.net.InetSocketAddress;

import io.netty.channel.ChannelHandlerContext;
import mylab.io.base.model.Endpoint;
import mylab.io.core.context.CoreContext;
import mylab.io.core.event.EndpointFoundEvent;
import mylab.utils.common.guava.AsyncEventUtil;

public class InboundFrameHandler extends AbstractInboundHandler {

    public InboundFrameHandler(CoreContext<?, ?> context) {
        super(context);
    }


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);

        //tcp连接，在连接建立时能发现对端
        if (ctx.channel().remoteAddress() instanceof InetSocketAddress socketAddress) {
            AsyncEventUtil.postEvent(new EndpointFoundEvent(ctx.channel(), Endpoint.from(socketAddress)));
        }
    }

}
